 package formulation;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class BeanFactory extends HttpServlet {

    private static final long serialVersionUID = 1L;
	private static WebApplicationContext context = null;
    
    public BeanFactory() {
        super();
    }
    
    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
        ServletContext ctx = getServletContext();
        context = WebApplicationContextUtils.getWebApplicationContext(ctx);
    }
    
    public static WebApplicationContext getWebApplicationContext() {
        return context;
    }
    
    public static Object getBean(String name) {
        return context.getBean(name);
    }
    
    // nothing to do
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
